package com.luo.chengrui.module.sa.api.permission;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import com.luo.chengrui.module.sa.api.permission.dto.DeptDataPermissionRespDTO;
import com.luo.chengrui.module.sa.api.permission.dto.UserDataPermissionRespDTO;
import com.luo.chengrui.module.sa.service.datapermission.DataPermissionDetailService;
import com.luo.chengrui.module.sa.service.role.PermissionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Set;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class SaPermissionApiImpl implements SaPermissionApi {

    @Resource
    private PermissionService permissionService;
    @Resource
    private DataPermissionDetailService dataPermissionDetailService;

    @Override
    public CommonResult<Set<Long>> getUserRoleIdListByRoleIds(Collection<Long> roleIds) {
        return null;
    }

    @Override
    public CommonResult<Boolean> hasAnyPermissions(Long userId, String... permissions) {
        return success(permissionService.hasAnyPermissions(userId, permissions));
    }

    @Override
    public CommonResult<Boolean> hasAnyRoles(Long userId, String... roles) {
        return success(true);
    }

    @Override
    public CommonResult<DeptDataPermissionRespDTO> getDeptDataPermission(Long userId) {
        return null;
    }

    @Override
    public CommonResult<UserDataPermissionRespDTO> getUserDataPermissionByCode(Long userId, String permissionCode) {
        //本地缓存
//        UserDataPermissionRespDTO result = dataPermissionDetailService.getUserDataPermissionByCode(userId, permissionCode)
        // redis缓存
        UserDataPermissionRespDTO result = dataPermissionDetailService.getUserDataPermissionByCodeFromRedis(userId, permissionCode);
        return success(result);
    }
}
